import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '控制台', icon: 'el-icon-user-solid' }
    }]
  },

  {
    path: '/user',
    component: Layout,
    redirect: '/user/userList',
    name: 'user',
    meta: { title: '用户管理', icon: 'el-icon-setting' },
    children: [
      {
        path: 'userList',
        name: 'userList',
        component: () => import('@/views/user/UserList'),
        meta: { title: '用户展示', icon: 'el-icon-s-data' }
      },
      {
        path: 'userAdd',
        name: 'userAdd',
        hidden:true,
        component: () => import('@/views/user/UserAdd'),
        meta: { title: '新增用户', icon: 'el-icon-circle-plus' }
      },
      {
        path: 'accessory',
        name: 'accessory',
        component: () => import('@/views/user/accessory'),
        meta: { title: '附件管理', icon: 'el-icon-picture-outline' }
      },
      {
        path: 'menu',
        name: 'menu',
        component: () => import('@/views/user/menu'),
        meta: { title: '菜单权限', icon: 'el-icon-tickets' }
      },
      {
        path: 'department',
        name: 'department',
        component: () => import('@/views/user/department'),
        meta: { title: '部门管理', icon: 'el-icon-s-home' }
      },
      {
        path: 'role',
        name: 'role',
        component: () => import('@/views/user/role'),
        meta: { title: '角色管理', icon: 'el-icon-postcard' }
      },
      {
        path: 'notice',
        name: 'notice',
        component: () => import('@/views/user/notice'),
        meta: { title: '公告管理', icon: 'el-icon-edit' }
      }
    ]
  },{
    path: '/business',
    component: Layout,
    name: 'business',
    meta: {title: '业务管理', icon: 'el-icon-s-cooperation'},
    children: [
      {
        path: 'addStocks',
        name: 'addStocks',
        component: () => import('@/views/business/AddStocks'),
        meta: {title: '物资入库', icon: 'el-icon-plus'}
      },
      {
        path: '/productManager',
        component: () => import('@/views/business/productManager'),
        name: 'productManager',
        meta: {title: '物资管理', icon: 'el-icon-date'},
        children: [
          {
            path: 'inStocks',
            name: 'inStocks',
            component: () => import('@/views/business/productManager/InStocks'),
            meta: {title: '入库记录', icon: 'el-icon-date'}
          },
          {
            path: 'productInfos',
            name: 'productInfos',
            component: () => import('@/views/business/productManager/ProductInfos'),
            meta: {title: '物资资料', icon: 'el-icon-goods'}
          },
          {
            path: 'productCategorys',
            name: 'productCategorys',
            component: () => import('@/views/business/productManager/ProductCategorys'),
            meta: {title: '物资类别', icon: 'el-icon-star-off'}
          },
          {
            path: 'outStocks',
            name: 'outStocks',
            component: () => import('@/views/business/productManager/OutStocks'),
            meta: {title: '发放记录', icon: 'el-icon-goods'}
          },
          {
            path: 'stocks',
            name: 'stocks',
            component: () => import('@/views/business/productManager/Stocks'),
            meta: {title: '物资库存', icon: 'el-icon-edit'}
          }
        ]
      },
      {
        path: '/productConsumer',
        component: () => import('@/views/business/productConsumer'),
        name: 'productConsumer',
        meta: {title: '物资流向', icon: 'el-icon-coordinate'},
        children: [
          {
            path: 'consumers',
            name: 'consumers',
            component: () => import('@/views/business/productConsumer/Consumers'),
            meta: {title: '物资去处', icon: 'el-icon-edit'}
          },
          {
            path: 'suppliers',
            name: 'Suppliers',
            component: () => import('@/views/business/productConsumer/Suppliers'),
            meta: {title: '物资来源', icon: 'el-icon-coordinate'}
          }
        ]
      }
    ]
  },{
    path: '/others',
    component: Layout,
    meta: {title: '其他管理', icon: 'el-icon-s-marketing'},
    children: [
      {
        path: 'control',
        component: () => import('@/views/others/control'),
        name: 'control',
        meta: {title: '监控管理', icon: 'el-icon-warning'},
        alwaysShow: true,
        children: [
          {
            path: 'druid',
            name: 'druid',
            component: () => import('@/views/others/control/Druid'),
            meta: {title: 'SQL监控', icon: 'el-icon-view'},
          }
        ]
      },
      {
        path: 'icons',
        name: 'icons',
        component: () => import('@/views/others/Icons'),
        meta: {title: '图标管理', icon: 'el-icon-edit'}
      },
      {
        path: 'qq',
        name: 'qq',
        component: () => import('@/views/others/QQ'),
        meta: {title: 'QQ交流群', icon: 'el-icon-view'}
      },
      {
        path: 'swagger',
        name: 'swagger',
        component: () => import('@/views/others/Swagger'),
        meta: {title: '项目文档', icon: 'el-icon-document'}
      }
    ]
  },{
    path: '/health',
    component: Layout,
    meta: {title: '员工健康', icon: 'el-icon-platform-eleme'},
    children: [
      {
        path: 'rumors',
        name: 'rumors',
        component: () => import('@/views/health/Rumors'),
        meta: {title: '疫情辟谣', icon: 'el-icon-help'}
      },
      {
        path: 'countryMap',
        name: 'countryMap',
        component: () => import('@/views/health/CountryMap.vue'),
        meta: {title: '全国疫情', icon: 'el-icon-s-opportunity'}
      },
      {
        path: 'healthClock',
        name: 'healthClock',
        component: () => import('@/views/health/Health'),
        meta: {title: '健康打卡', icon: 'el-icon-s-cooperation'}
      }
    ]
  },{
    path: '/log',
    component: Layout,
    meta: {title: '日志管理', icon: 'el-icon-camera'},
    children: [
      {
        path: 'loginLog',
        name: 'loginLog',
        component: () => import('@/views/log/LoginLog'),
        meta: {title: '登入日志', icon: 'el-icon-date'}
      },
      {
        path: 'logControl',
        name: 'logControl',
        component: () => import('@/views/log/LogControl'),
        meta: {title: '操作日志', icon: 'el-icon-edit'}
      }
    ]
  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
